import string
import time

import numpy as np

samples = ['The cat sat on the mat.', 'The dog ate my homework.']
# 所有可打印的ASCLL字符(0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)
chardeters = string.printable
# 先取1-100的数字，与chardeters合并压缩为元组，最后处理为字典数据
token_index = dict(zip(range(1, len(chardeters) + 1), chardeters))
max_length = 50
# 创建 len(samples)维度,max_length行，max(token_index.keys()) + 1列的全零数组
results = np.zeros((len(samples), max_length, max(token_index.keys()) + 1))
# enumerate（枚举）
for i, sample in enumerate(samples):
    for j, chardeter in enumerate(sample):
        # 返回字典对应值,如果没有返回None
        index = token_index.get(chardeter)
        results[i, j, index] = 1.

print(results)
